// 类
// class
// ts增强了class相关语法

class Person {
    public name:string
    private age:number// 类的属性使用之前需要先定义
    protected readonly gender:boolean
    constructor (name:string, age:number){
        this.name = name
        this.age = age
        this.gender = true
    }

    sayHi(msg:string):void {
        console.log(msg)
    }
}

// 访问修饰符

const tom = new Person('tom',12)
console.log(tom.name)
// console.log(tom.age)
// console.log(tom.gender)

class Students extends Person {
    private constructor(name:string, age:number){// private只能在内部中使用
        super(name,age)
        console.log(this.gender) // gender 只能在此类中访问
    }
}


// 类与接口
// 类与类之间使用接口联系
// 不同的类型使用相同的接口

interface Eat {
    eat(food: string):void 
}
interface Run {
    run(distance: number):void 
}
class Person1 implements Eat,Run{
    eat(food: string) {
        console.log(`人吃${food}`)
    }
    run(distance: number) {

    }
}

class Animal1 {
    eat(food: string) {
        console.log(`动物吃${food}`)
    }
}

// 泛型

function createArr<T>(length:number,value:T) {
    return Array<T>(length).fill(value)
}
createArr<string>(2,'100')

// 类型声明
// 应用第三方模块
// 安装声明模块
declare function camelCase(input:string):string

camelCase('aaa ssd')



